package chapter3.No3_1_等待和通知机制.a不使用等待通知机制实现线程间通信;

/**
 * Created by Administrator on 2016/11/16.
 */
public class ThreadB extends Thread {
    ServiceClass sc;

    public ThreadB(ServiceClass sc) {
        this.sc = sc;
    }

    @Override
    public void run() {
        try {
            while (true) {
                if (sc.size() == 5) {
                    System.out.println("里面的元素等于5个，退出");
                    throw new InterruptedException("已经到达5个，抛出异常");
                }
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
